package com.xqb.modules.controller.study;

import com.xqb.common.annotation.Log;
import com.xqb.common.core.controller.BaseController;
import com.xqb.common.core.domain.AjaxResult;
import com.xqb.common.core.page.TableDataInfo;
import com.xqb.common.enums.BusinessType;
import com.xqb.common.utils.poi.ExcelUtil;
import com.xqb.modules.domain.dto.LearningRecordFormDTO;
import com.xqb.modules.domain.po.StdLearningRecord;
import com.xqb.modules.service.IStdLearningRecordService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 学习记录Controller
 * 
 * @author xqb
 * @date 2024-10-14
 */
@RestController
@RequestMapping("/study/learning_record")
public class StdLearningRecordController extends BaseController
{
    @Autowired
    private IStdLearningRecordService stdLearningRecordService;

    /**
     * 查询学习记录列表
     */
    @PreAuthorize("@ss.hasPermi('study:learning_record:list')")
    @GetMapping("/list")
    public TableDataInfo list(StdLearningRecord stdLearningRecord)
    {
        startPage();
        List<StdLearningRecord> list = stdLearningRecordService.selectStdLearningRecordList(stdLearningRecord);
        return getDataTable(list);
    }

    /**
     * 导出学习记录列表
     */
    @PreAuthorize("@ss.hasPermi('study:learning_record:export')")
    @Log(title = "学习记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StdLearningRecord stdLearningRecord)
    {
        List<StdLearningRecord> list = stdLearningRecordService.selectStdLearningRecordList(stdLearningRecord);
        ExcelUtil<StdLearningRecord> util = new ExcelUtil<StdLearningRecord>(StdLearningRecord.class);
        util.exportExcel(response, list, "学习记录数据");
    }

    /**
     * 获取学习记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('study:learning_record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(stdLearningRecordService.selectStdLearningRecordById(id));
    }
    /**
     * 修改学习记录
     */
    @PreAuthorize("@ss.hasPermi('study:learning_record:edit')")
    @Log(title = "学习记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StdLearningRecord stdLearningRecord)
    {
        return toAjax(stdLearningRecordService.updateStdLearningRecord(stdLearningRecord));
    }

    /**
     * 删除学习记录
     */
    @PreAuthorize("@ss.hasPermi('study:learning_record:remove')")
    @Log(title = "学习记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(stdLearningRecordService.deleteStdLearningRecordByIds(ids));
    }

    @ApiOperation("提交学习记录")
    @Log(title = "学习记录", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('study:learning_record:add')")
    @PostMapping
    public AjaxResult addLearningRecord(@RequestBody LearningRecordFormDTO formDTO) {
        stdLearningRecordService.addLearningRecord(formDTO);
        return success();
    }
}
